﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Usuarios.ascx.cs" Inherits="CustomControls_Usuarios" %>

<div class="form">
    <div class="required-message">Los campos indicados con <span class="required-mark">*</span> son requeridos</div>
    <fieldset><legend>&nbsp;Detalles del Usuario&nbsp;</legend>
        <div class="field-line">
            <asp:Label CssClass="left" runat="server" ID="lblName" AssociatedControlID="txtName" Text="<span class='required-mark'>*</span> Nombre"></asp:Label>
            <asp:TextBox ID="txtName" CssClass="field" runat="server" Text=''  MaxLength="255"></asp:TextBox>
            <asp:RequiredFieldValidator ID="FNvalidator" runat="server" Display="Dynamic" ForeColor="Red" SetFocusOnError="true"
                ControlToValidate="txtName" ErrorMessage="Requerido"></asp:RequiredFieldValidator>
        </div>
        <div class="field-line">
            <asp:Label runat="server" CssClass="left" ID="lblLastName" AssociatedControlID="txtLastName" Text="<span class='required-mark'>*</span> Apellido"></asp:Label>
            <asp:TextBox ID="txtLastName" CssClass="field" runat="server" Text=''  MaxLength="255"></asp:TextBox>
            <asp:RequiredFieldValidator ID="LNvalidator" runat="server" Display="Dynamic" ForeColor="Red" SetFocusOnError="true"
                ControlToValidate="txtLastName" ErrorMessage="Requerido"></asp:RequiredFieldValidator>
        </div>
        <div class="field-line">
            <asp:Label runat="server" CssClass="left" ID="lblEmail" AssociatedControlID="txtEmail" Text="&nbsp;&nbsp;&nbsp;Email"></asp:Label>
            <asp:TextBox ID="txtEmail" CssClass="short-field" runat="server" Text=''  MaxLength="255"></asp:TextBox>
            <asp:RegularExpressionValidator ForeColor="Red" ControlToValidate="txtEmail" ID="regEmail" runat="server" ErrorMessage="Formato de email invalido" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
        </div>
         <div class="field-line">
            <asp:Label runat="server" CssClass="left" ID="lblRole" AssociatedControlID="drpRole" Text="<span class='required-mark'>*</span> Role"></asp:Label>
            <asp:DropDownList ID="drpRole" runat="server"   MaxLength="255">
            </asp:DropDownList>

        </div>
        <div class="field-line">
            <asp:Label runat="server" CssClass="left" ID="lblActivo" AssociatedControlID="chkEnabled" Text="&nbsp;&nbsp;&nbsp;Est&aacute; Activo?"></asp:Label>
            <asp:CheckBox runat="server"  ID="chkEnabled" />
        </div>
        <div class="field-line">
            <asp:Label runat="server" CssClass="left" ID="lblUsername" AssociatedControlID="txtUsername" Text="<span class='required-mark'>*</span> Username"></asp:Label>
            <asp:TextBox ID="txtUsername" CssClass="short-field" runat="server" Text=''  MaxLength="255"></asp:TextBox>
            <asp:RequiredFieldValidator ID="UNvalidator" runat="server" Display="Dynamic" ForeColor="Red" SetFocusOnError="true"
                ControlToValidate="txtUsername" ErrorMessage="Requerido"></asp:RequiredFieldValidator>
        </div>
        <a id="lnkChangePassword"  CausesValidation="false" class="change-password" style="display:none" runat="server"  href="javascript:void(0)">Cambiar Contrase&ntilde;a</a>
        <asp:Panel ID="pnlPassword" runat="server">
            <div class="field-line">
                <asp:Label runat="server" CssClass="left" ID="lblPassword" AssociatedControlID="txtPassword" Text="<span class='required-mark'>*</span> Contrase&ntilde;a"></asp:Label>
                <asp:TextBox ID="txtPassword" CssClass="short-field" TextMode="Password" runat="server" Text=''  MaxLength="255"></asp:TextBox>
                <asp:RequiredFieldValidator ID="Cvalidator" runat="server" Display="Dynamic" ForeColor="Red" SetFocusOnError="true"
                    ControlToValidate="txtPassword" ErrorMessage="Requerido"></asp:RequiredFieldValidator>
            </div>
        <div class="clear"></div>

            <div class="field-line">
                <asp:Label runat="server" CssClass="left" ID="lblConfPassword" AssociatedControlID="txtConfPassword" Text="<span class='required-mark'>*</span> Confirmar Contrase&ntilde;a"></asp:Label>
                <asp:TextBox ID="txtConfPassword" TextMode="Password" CssClass="short-field" runat="server" Text=''  MaxLength="255"></asp:TextBox>
                <asp:RequiredFieldValidator ID="CCvalidator" runat="server" Display="Dynamic" ForeColor="Red" SetFocusOnError="true"
                    ControlToValidate="txtConfPassword" ErrorMessage="Requerido"></asp:RequiredFieldValidator>
                <asp:CompareValidator ID="cmpPassword" ForeColor="red" runat="server" ControlToCompare="txtPassword" ControlToValidate="txtConfPassword" ErrorMessage="Contrase&ntilde;a y Confirmar Contrase&ntilde;a deben ser iguales"></asp:CompareValidator>
            </div>
        </asp:Panel>
        <div class="clear"></div>
        
        <asp:HiddenField runat="server" ID="hdnChangePassword" />
        <div class="clear"></div>
      
    <div class="buttons-actions">
            <asp:Button OnClientClick="Validate();" runat="server" ID="btnSave" OnClick="btnSave_Click" Text="Guardar" />
            <asp:Button runat="server" ID="btnCancel" OnClick="btnCancel_Click" CausesValidation="false" Text="Cancelar" />
        </div>
    </fieldset>
    <script>
        $(document).ready(function () {
            $("#<%= lnkChangePassword.ClientID  %>").click(function () {
                
                if ($("#<%= hdnChangePassword.ClientID  %>").val() == "0") {
                    $("#<%= hdnChangePassword.ClientID  %>").val("1");
                    $("#<%= lnkChangePassword.ClientID  %>").html("Cancelar cambio de Contrase&ntilde;a");
                    $("#<%= pnlPassword.ClientID  %>").css("display", "block");

                }
                else {
                    $("#<%= hdnChangePassword.ClientID  %>").val("0");
                    $("#<%= lnkChangePassword.ClientID  %>").html("Cambiar Contrase&ntilde;a");
                    $("#<%= pnlPassword.ClientID  %>").css("display", "none");

                }
            });
            
        });
        function Validate() {
            if ($("#<%= hdnChangePassword.ClientID  %>").val() == "1") {
                if ($("#<%= txtPassword.ClientID  %>").val() == "") {
                    ValidatorEnable($('[id$=Cvalidator]')[0], true);
                }
                if ($("#<%= txtConfPassword.ClientID  %>").val() == "") {
                    ValidatorEnable($('[id$=CCvalidator]')[0], true);
                }
                if ($("#<%= txtPassword.ClientID  %>").val() != "" && $("#<%= txtConfPassword.ClientID  %>").val() != ""
                    && $("#<%= txtPassword.ClientID  %>").val() != $("#<%= txtConfPassword.ClientID  %>").val()) {
                    ValidatorEnable($('[id$=cmpPassword]')[0], true);
                }
            }
            else {
                ValidatorEnable($('[id$=Cvalidator]')[0], false);
                ValidatorEnable($('[id$=CCvalidator]')[0], false);
                ValidatorEnable($('[id$=cmpPassword]')[0], false);
            }
        }
</script>
</div>    